﻿using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using TSharp.Core.Aop.Handler;

namespace TSharp.Core.Aop.Attributes
{
	/// <summary>
	/// 验证定制特性
	/// </summary>
	public class ValidationAttribute : HandlerAttribute
	{
		//public TransactionAttribute(string dataBaseName, bool isDistributed)
		//{
		//    DataBaseName = dataBaseName;
		//    IsDistributed = isDistributed;
		//}
		/// <summary>
		/// 验证定制特性
		/// </summary>
		/// <param name="type">指定一个验证的类型</param>
		public ValidationAttribute(Type type)
		{
			Type = type;
			Order = 1;
		}

		/// <summary>
		/// 验证定制特性，只验证方法参数
		/// </summary>
		public ValidationAttribute()
			: this(null)
		{
		}

		/// <summary>
		/// 验证类型名称
		/// </summary>
		public Type Type { get; set; }

		//public TransactionAttribute()
		//    : this(string.Empty, false)
		//{
		//}
		/// <summary>
		/// 数据库名称
		/// </summary>
		public string DataBaseName { get; set; }

		/// <summary>
		/// 数据库名称
		/// </summary>
		public bool IsDistributed { get; set; }

		/// <summary>
		/// Derived classes implement this method. When called, it
		/// creates a new call handler as specified in the attribute
		/// configuration.
		/// </summary>
		/// <param name="container">The <see cref="T:Microsoft.Practices.Unity.IUnityContainer"/> to use when creating handlers,
		/// if necessary.</param>
		/// <returns>A new call handler object.</returns>
		public override ICallHandler CreateHandler(IUnityContainer container)
		{
			return new ValidationHandler(Type, Order);
		}
	}
}